﻿ IF EXISTS (SELECT * FROM sysobjects WHERE type = 'FN' AND name = 'ufn_UPDMS_Get_Day_Count_Of_Month')
	BEGIN
		DROP Function ufn_UPDMS_Get_Day_Count_Of_Month
	END
GO

SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO
/******************************************************************************
**	Name : ufn_UPDMS_Get_Day_Count_Of_Month
**	Desc : 특정월의 일수를 리턴
**	Test Exec Query : SELECT dbo.ufn_UPDMS_Get_Day_Count_Of_Month('2014-06')
**	Called by : 전체
**	Program ID : 전체
**	Auth : 송시명
**	Date : 2014-06-20
*******************************************************************************
**	Change History
*******************************************************************************
**	Date:		Author:		Description: 
**	--------	--------	---------------------------------------
**	
*******************************************************************************/
CREATE FUNCTION [dbo].[ufn_UPDMS_Get_Day_Count_Of_Month]
(
@ls_yyyymm varchar(10)
)
RETURNS varchar(2)
AS

BEGIN
    DECLARE @rtn nvarchar(2)
    SET @rtn = ''
	
    SELECT @rtn = DATEPART(day,DATEADD(d, -DATEPART(day,CONVERT(DATETIME,LEFT(@ls_yyyymm, 7) + '-01')),DATEADD(m,1,CONVERT(DATETIME,LEFT(@ls_yyyymm, 7) + '-01'))))
  
    RETURN LTRIM(RTRIM(@rtn))
END